package com.jiyun.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jiyun.model.information.MiddleTableItempmService;
import com.jiyun.model.information.ZlItempm;
import com.jiyun.model.information.ZlTeam;
import com.jiyun.oss.AliyunOSSUtils;
import com.jiyun.result.Result;
import com.jiyun.service.IMiddleTableItempmServiceService;
import com.jiyun.service.IZlItempmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-09-23
 */
@RestController
@RequestMapping("/itempm/")
@Api("服务项目管理")
@Slf4j
public class ZlItempmController {

    @Autowired
    private IZlItempmService zlItempmService;

    @Autowired
    private IMiddleTableItempmServiceService middleTableItempmServiceService;

    @ApiModelProperty("服务项目管理分页查询接口（根据名称和介绍模糊查询）")
    @RequestMapping("findPage/{pn}/{ps}")
    public Result findPage(@PathVariable Integer pn, @PathVariable Integer ps, @RequestBody ZlItempm zlItempm) {
//        log.info("条件查询：" + zlItempm);
        IPage<ZlItempm> page = zlItempmService.findPage(pn, ps, zlItempm);
//        log.info("分页查询结果：" + page);
        return Result.ok(page);
    }

    @ApiModelProperty("查询所有")
    @RequestMapping("findItempm")
    public Result findDoctor(){
        return Result.ok(zlItempmService.list());
    }

    @ApiModelProperty("查询多个")
    @RequestMapping("findId")
    public Result findId(@RequestBody List<Integer> ids){
        List<ZlItempm> zlItempms = zlItempmService.listByIds(ids);
//        System.err.println(zlItempms);
        return Result.ok(zlItempms);
    }


    @ApiModelProperty("添加或修改服务项目管理信息")
    @RequestMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ZlItempm zlItempm) {
//        log.info("添加或修改服务项目管理信息：" + zlItempm);
       if (zlItempm.getId() == null){
          zlItempmService.saveOrUpdate(zlItempm);
       }else {
           zlItempmService.updateById(zlItempm);
       }
        return Result.ok();
    }


    @ApiModelProperty("删除")
    @RequestMapping("delete/{id}")
    public Result delete(@PathVariable Long id) {
//        log.info("删除id：" + id);
        zlItempmService.removeById(id);
//        中间表删除
        middleTableItempmServiceService.remove(new QueryWrapper<MiddleTableItempmService>().
                eq("iid", id));
        return Result.ok();
    }




}
